package com.yc.bran.snack.bean;

import java.time.LocalDate;
import javax.persistence.Id;

import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document;


@Document(collection = "comment") 
public class Comment {
	@Id 
	private ObjectId id; // MongoDB自动生成ObjectId，这里为了简单起见使用String
	private int commentPrId; // 评论文章所属id
	private int gid;	// 商品id
	private String commentUserAvatar; // 评论用户头像  
	private String commentUserName; // 评论人昵称  
	private String commentText; // 评论内容  
	private LocalDate commentTime; // 评论时间  

	@Override
	public String toString() {
		return "Comment [id=" + id + ", commentPrId=" + commentPrId + ", gid=" + gid + ", commentUserAvatar="
				+ commentUserAvatar + ", commentUserName=" + commentUserName + ", commentText=" + commentText
				+ ", commentTime=" + commentTime + "]";
	}

	public Comment(ObjectId id, int commentPrId, int gid, String commentUserAvatar, String commentUserName,
			String commentText, LocalDate commentTime) {
		super();
		this.id = id;
		this.commentPrId = commentPrId;
		this.gid = gid;
		this.commentUserAvatar = commentUserAvatar;
		this.commentUserName = commentUserName;
		this.commentText = commentText;
		this.commentTime = commentTime;
	}

	public Comment() {
		super();
	}

	public String getIdAsString() {  
		return id != null ? id.toHexString() : null;  
	}  

	// 如果需要，可以添加一个方法来设置ID（通常不需要，因为是由MongoDB自动设置的）  
	public void setId(ObjectId id) {  
		this.id = id;  
	}

	public int getCommentPrId() {
		return commentPrId;
	}

	public void setCommentPrId(int commentPrId) {
		this.commentPrId = commentPrId;
	}

	public int getGid() {
		return gid;
	}

	public void setGid(int gid) {
		this.gid = gid;
	}

	public String getCommentUserAvatar() {
		return commentUserAvatar;
	}

	public void setCommentUserAvatar(String commentUserAvatar) {
		this.commentUserAvatar = commentUserAvatar;
	}

	public String getCommentUserName() {
		return commentUserName;
	}

	public void setCommentUserName(String commentUserName) {
		this.commentUserName = commentUserName;
	}

	public String getCommentText() {
		return commentText;
	}

	public void setCommentText(String commentText) {
		this.commentText = commentText;
	}

	public LocalDate getCommentTime() {
		return commentTime;
	}

	public void setCommentTime(LocalDate commentTime) {
		this.commentTime = commentTime;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + commentPrId;
		result = prime * result + ((commentText == null) ? 0 : commentText.hashCode());
		result = prime * result + ((commentTime == null) ? 0 : commentTime.hashCode());
		result = prime * result + ((commentUserAvatar == null) ? 0 : commentUserAvatar.hashCode());
		result = prime * result + ((commentUserName == null) ? 0 : commentUserName.hashCode());
		result = prime * result + gid;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Comment other = (Comment) obj;
		if (commentPrId != other.commentPrId)
			return false;
		if (commentText == null) {
			if (other.commentText != null)
				return false;
		} else if (!commentText.equals(other.commentText))
			return false;
		if (commentTime == null) {
			if (other.commentTime != null)
				return false;
		} else if (!commentTime.equals(other.commentTime))
			return false;
		if (commentUserAvatar == null) {
			if (other.commentUserAvatar != null)
				return false;
		} else if (!commentUserAvatar.equals(other.commentUserAvatar))
			return false;
		if (commentUserName == null) {
			if (other.commentUserName != null)
				return false;
		} else if (!commentUserName.equals(other.commentUserName))
			return false;
		if (gid != other.gid)
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}